package pl.edu.agh.uddiProxy.dao;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import pl.edu.agh.uddiProxy.UDDIClient;
import pl.edu.agh.uddiProxy.types.ParametersMap;

public class DAOHelper {
	private static DynamicParameterDAO dynamicParameterDAO;
	private static DynamicParameterDAO testDynamicParameterDAO;
	private static UDDIClient client;
	private static ParametersMap parametersMap;
	private static ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "context.xml" });
	
	public static DynamicParameterDAO getDynamicParameterDAO() {
		if (dynamicParameterDAO == null) {
			dynamicParameterDAO = (DynamicParameterDAO) context.getBean("DynamicParameterDAO");
		}
		return dynamicParameterDAO;
	}
	
	public static UDDIClient getUDDIClient() {
		if (client == null) {
			client = (UDDIClient) context.getBean("UDDIClient");
		}
		return client;
	}
	
	public static DynamicParameterDAO getTestDynamicParameterDAO() {
		if (testDynamicParameterDAO == null) {
			testDynamicParameterDAO = (DynamicParameterDAO) context.getBean("TestDynamicParameterDAO");
		}
		return testDynamicParameterDAO;
	}
	
	public static void test() {
		if (testDynamicParameterDAO == null || dynamicParameterDAO == null) {
			getTestDynamicParameterDAO();
			getDynamicParameterDAO();
		}
		dynamicParameterDAO = testDynamicParameterDAO;
	}

	public static ParametersMap getParametersMap() {
		if (parametersMap == null) {
			parametersMap = (ParametersMap) context.getBean("ParametersMap");
		}
		return parametersMap;
	}
	
	
}
